package com.zoro.dyformservice.business.blog.repository;

import com.zoro.dyformservice.business.blog.entity.IUserBlogBasic;
import com.zoro.dyformservice.business.blog.entity.UserBlog;
import com.zoro.dyformservice.business.blog.entity.UserBlogBasic;
import com.zoro.dyformservice.business.blog.entity.UserBlogBasicRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface UserBlogRepository extends JpaRepository<UserBlog, String> {

    IUserBlogBasic findByBlogId(String id);

    List<UserBlogBasic> findByBlogTitle(String title);

    List<UserBlogBasicRecord> findByUserInfoUserId(String userID);

    @Query("""
            select new com.zoro.dyformservice.business.blog.entity.UserBlogBasic(t.blogId,t.blogTitle, t.createDate)
             from UserBlog t where t.blogTitle = :title
            """)
    List<UserBlogBasic> findUserBlog(String title);

    @Query("""
            select new com.zoro.dyformservice.business.blog.entity.UserBlogBasicRecord(t.blogId,t.blogTitle, t.createDate)
             from UserBlog t where t.blogTitle = :title
            """)
    List<UserBlogBasicRecord> findUserBlog2(String title);

    <T> List<T> findByUserInfoUserIdAndBlogTitle(String id, String title, Class<T> clazz);

}
